<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

use app\common\model\ForumBbsCategory;
use app\common\model\ForumBbsLevel;

/**
 * 论坛话题控制器
 */
class Bbs extends AdminBase
{
    
    /**
     * 论坛话题列表
     */
    public function articleList()
    {
        
       // $where = $this->logicBbs->getWhere($this->param);

        $this->assign('list', $this->logicBbs->getArticleList($this->param, 'a.*,m.nickname,c.name as category_name', 'a.create_time desc'));
        $this->assign('cate', ForumBbsCategory::all(['status'=>1]));
        $this->assign('tags', ForumBbsLevel::all(['status'=>1]));
        return $this->fetch('article_list');
    }


    /**
     * 未审核论坛话题列表
     */
    public function articleList1()
    {

        // $where = $this->logicBbs->getWhere($this->param);
        $this->param['state']=0;
        $this->assign('list', $this->logicBbs->getArticleList($this->param, 'a.*,m.nickname,c.name as category_name', 'a.create_time desc'));
        $this->assign('cate', ForumBbsCategory::all(['status'=>1]));
        $this->assign('tags', ForumBbsLevel::all(['status'=>1]));
        return $this->fetch('article_list1');
    }

    /**
     * 论坛话题回帖列表
     */
    public function articleList3()
    {

        // $where = $this->logicBbs->getWhere($this->param);
        $this->assign('list', $this->logicBbs->getCommentList($this->param, 'a.*,m.nickname', 'a.create_time desc'));
        return $this->fetch('article_list3');
    }


    /**
     * 论坛话题添加
     */
    public function articleAdd()
    {
        
        $this->articleCommon();
        $this->assign('user_id', $this->param['user_id']);
        return $this->fetch('article_edit');
    }
    
    /**
     * 论坛话题编辑
     */
    public function articleEdit()
    {
        
        $this->articleCommon();
        
        $info = $this->logicBbs->getArticleInfo(['a.id' => $this->param['id']], 'a.*,m.nickname,c.name as category_name');
        
        !empty($info) && $info['img_ids_array'] = str2arr($info['img_ids']);
        
        $this->assign('info', $info);
        $this->assign('tags', ForumBbsLevel::all(['status'=>1]));
        return $this->fetch('article_edit');
    }
    
    /**
     * 论坛话题添加与编辑通用方法
     */
    public function articleCommon()
    {
        
//      IS_POST && $this->jump($this->logicBbs->articleEdit($this->param));
        IS_POST && $this->jump($this->logicBbs->articleEdit($_POST));
        $this->assign('cate', ForumBbsCategory::all(['status'=>1]));
        $this->assign('tags', ForumBbsLevel::all(['status'=>1]));
        $this->assign('article_category_list', $this->logicBbs->getArticleCategoryList([], 'id,name', '', false));
    }
    
    /**
     * 论坛话题分类添加
     */
    public function articleCategoryAdd()
    {
        
        IS_POST && $this->jump($this->logicBbs->articleCategoryEdit($this->param));
        
        return $this->fetch('article_category_edit');
    }
    
    /**
     * 论坛话题分类编辑
     */
    public function articleCategoryEdit()
    {
        
        IS_POST && $this->jump($this->logicBbs->articleCategoryEdit($this->param));
        
        $info = $this->logicBbs->getArticleCategoryInfo(['id' => $this->param['id']]);
        
        $this->assign('info', $info);
        
        return $this->fetch('article_category_edit');
    }

    /**
     * 论坛话题分类列表
     */
    public function articleCategoryList()
    {
        
        $this->assign('list', $this->logicBbs->getArticleCategoryList());
       
        return $this->fetch('article_category_list');
    }
    
    /**
     * 论坛话题分类删除
     */
    public function articleCategoryDel($id = 0)
    {
        
        $this->jump($this->logicBbs->articleCategoryDel(['id' => $id]));
    }
    
    /**
     * 数据状态设置
     */
    public function setStatus()
    {
        
        $this->jump($this->logicAdminBase->setStatus('ForumBbs', $this->param));
    }

    /**
     * 数据状态设置
     */
    public function update_info()
    {

        $this->jump($this->logicBbs->update_info( $this->param));
    }


    /**
     * 隐藏/显示回帖
     */
    public function comment_update_info()
    {

        $this->jump($this->logicBbs->comment_update_info( $this->param));
    }


    /**
     * 论坛话题分类添加
     */
    public function articleLevelAdd()
    {

        IS_POST && $this->jump($this->logicBbs->articleLevelEdit($this->param));

        return $this->fetch('article_level_edit');
    }

    /**
     * 论坛话题分类编辑
     */
    public function articleLevelEdit()
    {

        IS_POST && $this->jump($this->logicBbs->articleLevelEdit($this->param));

        $info = $this->logicBbs->getArticleLevelInfo(['id' => $this->param['id']]);

        $this->assign('info', $info);

        return $this->fetch('article_level_edit');
    }

    /**
     * 论坛话题分类列表
     */
    public function articleLevelList()
    {

        $this->assign('list', $this->logicBbs->getArticleLevelList());

        return $this->fetch('article_level_list');
    }

    /**
     * 论坛话题分类删除
     */
    public function articleLevelDel($id = 0)
    {

        $this->jump($this->logicBbs->articleLevelDel(['id' => $id]));
    }
}
